package com.spring.sunflower.common;

import android.widget.ImageView;

import androidx.core.content.ContextCompat;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.android.material.button.MaterialButton;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.FansBean;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by Kevin on 2021/7/16<br/>
 * <p>
 * Describe:<br/>
 */
public class FansAdapter extends BaseQuickAdapter<FansBean.DatasBean, BaseViewHolder> {
    public FansAdapter(int layoutResId, @Nullable List<FansBean.DatasBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, FansBean.DatasBean bean) {
        Glide.with(getContext())
                .load(bean.getPhoto())
                .placeholder(R.drawable.ic_placeholder)
                .error(R.drawable.ic_placeholder)
                .into((ImageView) holder.getView(R.id.ivCover));
        holder.setText(R.id.tvName, bean.getNickname());
        holder.setText(R.id.tvMark, bean.getCity());
        MaterialButton btn = holder.getView(R.id.btnAction);
        boolean fans = bean.isFans();
        if (fans) {//粉丝列表
            if (bean.getIsFavorite().equals("1")) {//1表明我关注了对方
                btn.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.gray_4));
                btn.setText("互相关注");
            } else {
                btn.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
                btn.setText("关注TA");
            }
        } else {//关注列表
            if (bean.getIsFavorite().equals("1")) {//1表明对方也关注了我
                btn.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.gray_4));
                btn.setText("互相关注");
            } else {
                btn.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.colorPrimary));
                btn.setText("已关注");
            }
        }
    }
}
